/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.org.pslava.codingtest.model;

import java.io.Serializable;
import java.util.HashMap;
import ua.org.pslava.codingtest.delegates.ICalculateDelegate;

/**
 * Encapsulates a functionality of product entity. <br/>
 *
 * 
 * @author Vyacheslav Panasyuk.
 */
public class Product implements Serializable, IProduct {

    private String productName;
    private HashMap<Integer, Double> prices;
    private ICalculateDelegate delegate;

    public Product(String productName, ICalculateDelegate calcMethod) {
        this.productName = productName;
        this.delegate = calcMethod;
        prices = new HashMap<Integer, Double>();
    }

    public Product(String productName, HashMap<Integer, Double> prices) {
        this.productName = productName;
        this.prices = prices;
    }

    @Override
    public void addPrice(Integer count, double price) {
        prices.put(count, price);
    }

    @Override
    public HashMap<Integer, Double> getPrices() {
        return prices;
    }

    @Override
    public String getName() {
        return this.productName;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null) {
            return false;
        }

        if (!(o instanceof Product)) {
            return false;
        }

        if (this.productName.equals(((Product) o).getName())) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Double calculate(Integer count) {
        return delegate.calculate(count, prices);
    }
}
